$(function(){
	var birthday = $('[name="birthday"]').val();
	$("#userBirthday").datebox('setValue',birthday);
});


function myformatter(date) {
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	var d = date.getDate();
	return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
}
function myparser(s) {
	if (!s)
		return new Date();
	var ss = (s.split('-'));
	var y = parseInt(ss[0], 10);
	var m = parseInt(ss[1], 10);
	var d = parseInt(ss[2], 10);
	if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
		return new Date(y, m - 1, d);
	} else {
		return new Date();
	}
}
// 保存-修改
function submitUserPersonal() {
	// 修改
	var userId = $("#userId").val();
	var userRealname = $("#userRealname").val().replace(/(^\s*)|(\s*$)/g, "");
	var userAge = $("#userAge").val().replace(/(^\s*)|(\s*$)/g, "");
	var userBirthday = $('#userBirthday').datebox('getValue');
	var userSex = $("#userSex").combobox("getValue");
	var userPicture = $("#userPicture").combobox("getValue");
	var userPhone = $("#userPhone").val().replace(/(^\s*)|(\s*$)/g, "");
	var userHouse = $("#userHouse").val().replace(/(^\s*)|(\s*$)/g, "");
	var userWork = $("#userWork").val().replace(/(^\s*)|(\s*$)/g, "");
	var userEmail = $("#userEmail").val().replace(/(^\s*)|(\s*$)/g, "");
	var userPassword = $("#userPassword").val().replace(/(^\s*)|(\s*$)/g, "");
	var userNewPassword = $("#userNewPassword").val().replace(/(^\s*)|(\s*$)/g,
			"");
	if (userPassword == "" || userPassword == null) {
		if (userNewPassword != "" && userNewPassword != null) {
			$.messager.alert("提示信息", "原始密码为空！", "info");
			return false;
		}
	}
	if (userNewPassword == "" || userNewPassword == null) {
		if (userPassword != "" && userPassword != null) {
			$.messager.alert("提示信息", "新密码为空！", "info");
			return false;
		}
	}
	$.ajax({
		url : base + "/userInfo/saveUserPersonalInfo.action",
		type : "post",
		data : {
			"userId":userId,
			"userRealname":userRealname,
			"userAge":userAge,
			"userPicture":userPicture,
			"userBirthday":userBirthday,
			"userSex":userSex,
			"userPhone":userPhone,
			"userHouse":userHouse,
			"userWork":userWork,
			"userEmail":userEmail,
			"userPassword":userPassword,
			"userNewPassword":userNewPassword
		},
		cache : false,
		success : function(data) {
			if (!data.success) {
				$.messager.alert("提示信息", data.message, "info");
			} else {
				$.messager.alert("提示信息", "修改成功！", "success");
			}
			$.messager.progress('close');
		},
		async : false
	});
}
